package top.manbutech.ui.androidui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.Switch;

/**
 * Created by Administrator on 2018/8/25.
 */

public class PreferenceDemoActivity extends Activity implements CompoundButton.OnCheckedChangeListener {

    private static final String TAG = "PreferenceDemoActivity";
    private Switch mIsAllowSouce;
    private SharedPreferences mSharePreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preference_demo);

        Switch mIsAllowSouce =  (Switch) this.findViewById(R.id.is_allow_apps_sources);
        mIsAllowSouce.setOnCheckedChangeListener(this);
        mSharePreferences = this.getSharedPreferences("settings_info",MODE_PRIVATE);
        
    }


    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        //对数据进行保存 
        Log.d(TAG, "onCheckedChanged: "+b);

        SharedPreferences.Editor editor = mSharePreferences.edit();
        //传递值
        editor.putBoolean("state",b);
        //保存偏好值
        editor.commit();
    }
}
